<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="js/jquery.js">
</script>
<script>
var request;
function read(message_id){
	request=new XMLHttpRequest();
	request.open("post","readmessage.action?message_id="+message_id,true);
	request.send();
	request.onreadystatechange=display;
}
function display(){
	document.getElementById('loader').innerHTML=request.responseText;
	//reload();
}
function reload(){
	
}

</script>
<script language="JavaScript">
$(document).ready(function()
		{
	$('#search').keyup(function()
		    {
		        searchTable($(this).val());
		    });
		});

</script>
<script>
function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 
function searchTable(inputVal)
{
    var table = $('#example');
    table.find('tr').each(function(index, row)
    {
        var allCells = $(row).find('td');
        if(allCells.length > 0)
        {
            var found = false;
            allCells.each(function(index, td)
            {
                var regExp = new RegExp(inputVal, 'i');
                if(regExp.test($(td).text()))
                {
                    found = true;
                    return false;
                }
            });
            if(found == true)$(row).show();else $(row).hide();
        }
    });
}
</script>
</head>
<body>


<div align="left">
<a href="javascript:void(0);" onclick="PopupCenter('newstudentmessage.action','batch',600,600);">New Message</a>


</div>
	<div align="right">
		Search: <input type="text" name="search" id="search" />
	</div>
	<hr>
	<div align="center">Inbox</div>
	<table border="1" width="100%" id="example">
		
			<td width="40%">
				<table width="100%">
					<s:iterator value="unread">
						<div onclick="openmessage()" id="<s:property value="message_id"/>" style="display: block;cursor:pointer;">

							<tr>
								<td><font size="5"><b><s:property
												value="subject" /></b></font></td>
								<td><font size="2"><s:property
											value="attachment_count" /> attachments</font></td>
							</tr>
							<tr>
								<td><font size="3"><i><s:property
												value="sender_id" /></i></font>
												<br>		<hr>
												
												</td>
								<td><font size="2"><s:property value="sent_at"/> <input type="button" value="Read" onclick="read('<s:property value="message_id"/>')"/></font></td>				
											
							</tr>

						
						</div>
					</s:iterator>
					<s:iterator value="read">
						<div onclick="openmessage()" id="<s:property value="message_id"/>" style="display: block;cursor:pointer;">

							<tr>
								<td><font size="5"><s:property
												value="subject" /></font></td>
								<td><font size="2"><s:property
											value="attachment_count" /> attachments</font></td>
							</tr>
							<tr>
								<td><font size="3"><i><s:property
												value="sender_id" /></i></font>
												<br>		<hr>
												
												</td>
								<td><font size="2"><s:property value="sent_at"/> <input type="button" value="Read" onclick="read('<s:property value="message_id"/>')"/></font></td>				
											
							</tr>

						
						</div>
					</s:iterator>
				</table>
			</td>
		<td width="60%">	<table>
		
				<tr>
					<td><div id="loader"></div></td>
				</tr>

			</table>
		</td>
	</table>
</body>
</html>